import { IMG_PATH } from '../../../../config/index.js'
import { ApiRootUrl } from '../../../../config/index.js'
import Toast from '../../../../@vant/weapp/toast/toast';
import Dialog from '../../../../@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardFlag:true,
    maxxueli:'请选择',
    xueliListShow:false,
    username:'',
    usernameFlag:false,
    usercard:'',
    IMG_PATH:IMG_PATH,
    imgurl:`${IMG_PATH}/zhaopinhui/zhaopin1.png`,
    xueliShow:false,
    xueliList:[{
      id:'31',
      text:'大专毕业'
    },{
      id:'11',
      text:'博士'
    },{
      id:'14',
      text:'硕士'
    },{
      id:'20',
      text:'本科在读'
    },{
      id:'21',
      text:'本科毕业'
    },{
      id:'30',
      text:'大专在读'
    },{
      id:'41',
      text:'中专'
    },{
      id:'44',
      text:'职业高中'
    },{
      id:'47',
      text:'技工学校'
    },{
      id:'61',
      text:'高中'
    },{
      id:'71',
      text:'初中'
    }],
    detailsObj:{},
  },
  maxxueliClick(){
    this.setData({
      xueliListShow:true
    })
  },
  backClick() {
    wx.navigateBack();
  },
  xueliShowClose(){
    Toast('请完善信息！')
  },
  xueliListShowClose(){
    Toast('请选择最高学历！')
  },
  xueliShowListConfirm(event){
    let id = event.detail.value.id;
    let name = event.detail.value.text;
    console.log('id',id)
    console.log('name',name)
    this.setData({
      xueliListShow:false,
      currentId:id,
      currentName:name,
      maxxueli:name
    })
  },
  xueliShowConfirm(){
    let self = this;
    if(!self.data.username || !self.data.username.length){
      Toast('请输入姓名！')
      return;
    }
    if(!self.data.usercard || !self.data.usercard.length){
      Toast('请输入身份证！')
      return;
    }
    if(!self.data.currentName || !self.data.currentName.length){
      Toast('请选择最高学历！')
      return;
    }
    self.confirmMethod();
  },
  confirmMethod(){
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    let self = this;
    let params = {
      openId:wx.getStorageSync('openId'),
      name:self.data.username,
      identity:self.data.usercard,
      highEducational:self.data.currentId
    }
    wx.request({
      url: `${ApiRootUrl}/hire/editJobEmployeeInfo`,
      method: 'post',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      params:params,
      success(res) {
        Toast.clear();
        if(res.data.code == 20000){
          self.setData({
            xueliShow:false
          })
          wx.navigateTo({
            url: '../relation/relation',
          })
        }else{
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  usercardJiaoyan(){
    let self = this;
    if(!self.data.username || !self.data.usercard){
      Toast('请输入姓名和身份证!')
      return;
    }
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    let params = {
      name:self.data.username,
      identity:self.data.usercard
    }
    wx.request({
      url: `${ApiRootUrl}/labour/checkByPerson`,
      method: 'post',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      params:params,
      success(res) {
        Toast.clear();
        if(res.data.code == 20000){
          self.setData({
            cardFlag:false,
            usernameFlag:true
          })
          Toast('实名认证成功！')
        }else{
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  queryPosition(){
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    let self = this;
    let params = {
      openId:wx.getStorageSync('openId')
    }
    wx.request({
      url: `${ApiRootUrl}/hire/validateJobEmployeeInfo`,
      method: 'get',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      params:params,
      success(res) {
        Toast.clear();
        if(res.data.code == 20000){
          wx.setStorageSync('zhaopinObj', res.data.data)
          if(res.data.data){
            if(res.data.data.highEducational == null || res.data.data.name == null || res.data.data.identity == null){
              self.setData({
                xueliShow:true
              })
              if(res.data.data.name && res.data.data.identity){
                self.setData({
                  usernameFlag:true,
                  username:res.data.data.name,
                  usercard:res.data.data.identity
                })
              }else{
                self.setData({
                  usernameFlag:false
                })
              }
            }else{
              wx.navigateTo({
                url: '../relation/relation',
              });
            }
          }else{
            self.setData({
              xueliShow:true,
              usernameFlag:false,
            })
          }
        }else{
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id;
    wx.setStorageSync('zhaopinId',id)
    console.log('id---->:',id);
    this.queryList(id);
  },
  queryList(val){
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    let self = this;
    let params = {
      id:val
    }
    wx.request({
      url: `${ApiRootUrl}/hire/detailsJob`,
      method: 'get',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      params:params,
      success(res) {
        Toast.clear();
        if(res.data.code == 20000){
          let detailsObj = res.data.data;
          self.setData({
            detailsObj:detailsObj
          })
        }else{
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})